<!DOCTYPE html>
<html>

<head>
    <#include "/yq/admin/components/meta.html" />
    <title>蓁奕科技 ${metaTitleSuffix!}</title>
    <#include "/yq/admin/components/stylesheets.html" />
</head>

<body>
    <div id='app'>
        <el-container>
            <#assign menuIndex="2-2" />
            <#include "/yq/admin/components/menu.html" />
            <el-container>
                <#include "/yq/admin/components/header.html" />
                <el-main>
                    <template>
                        <!-- <el-button @click='onAdd'>新增</el-button> -->
                        <div class="search">
                            <!-- <el-date-picker v-model="dateRange" type="datetimerange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd HH:mm:ss" unlink-panels="true" :default-value="new Date">
                            </el-date-picker> -->
                            <el-select v-model="productId" placeholder="商品" filterable clearable>
                                <el-option v-for="item in products" :key="item.id" :label="item.title" :value="item.id">
                                </el-option>
                            </el-select>
                            <!-- <el-select v-model="shopId" clearable filterable placeholder="商户" v-if="${userRole!2} != 2">
                                <el-option v-for="item in shops" :key="item.id" :label="item.name" :value="item.id">
                                </el-option>
                            </el-select> -->
                            <!-- <el-select v-model="categoryId" clearable placeholder="商品类型">
                                <el-option :value="item.id" :label="item.title" v-for="(item, index) in categories"></el-option>
                            </el-select> -->
                            <el-select v-model="isDone" clearable placeholder="是否完成">
                                <el-option :value="0" label="未完成"></el-option>
                                <el-option :value="1" label="已完成"></el-option>
                            </el-select>
                            <el-select v-model="isClosed" clearable placeholder="是否关闭">
                                <el-option :value="0" label="未关闭"></el-option>
                                <el-option :value="1" label="已关闭"></el-option>
                            </el-select>
                            <el-button @click="onSearch"><i class="el-icon-search"></i>筛选</el-button>
                        </div>
                        <el-table :data="items" style="width: 100%">
                            <el-table-column type="expand">
                                <template slot-scope="props">
                                    <el-table :data="props.row.users" style="width: 100%">
                                        <el-table-column prop="nickName" label="用户昵称">
                                        </el-table-column>
                                        <el-table-column prop="mobile" label="手机">
                                        </el-table-column>
                                        <el-table-column prop="openId" label="openId">
                                        </el-table-column>
                                        <el-table-column prop="out_trade_no" label="商户单号">
                                            <template slot-scope="user">
                                                <el-button type="text" @click="window.location.href = '/yq/admin/order/info?orderId=' + user.row.orderId">{{ user.row.out_trade_no }}</el-button>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="status" label="状态">
                                            <template slot-scope="user">
                                                <span v-if='user.row.status == 1'>已支付</span>
                                                <span v-if='user.row.status == 0'>未支付</span>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="addTime" label="参团时间">
                                        </el-table-column>
                                    </el-table>
                                </template>
                            </el-table-column>
                            <el-table-column prop="title" label="商品标题">
                            </el-table-column>
                            <el-table-column prop="subtitle" label="商品副标题">
                            </el-table-column>
                            <el-table-column prop="nickName" label="发起用户">
                            </el-table-column>
                            <el-table-column prop="addTime" label="创建时间">
                            </el-table-column>
                            <el-table-column prop="expire" label="过期时间">
                            </el-table-column>
                            <el-table-column prop="count" label="拼团人数" width="80">
                            </el-table-column>
                            <el-table-column prop="isDone" label="是否完成" width="80">
                                <template slot-scope="scope">
                                    <span v-if='scope.row.isDone == 1'>已完成</span>
                                    <span v-if='scope.row.isDone == 0'>未完成</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="isClosed" label="是否关闭" width="80">
                                <template slot-scope="scope">
                                    <span v-if='scope.row.isClosed == 1'>已关闭</span>
                                    <span v-if='scope.row.isClosed == 0'>未关闭</span>
                                </template>
                            </el-table-column>
                            <el-table-column label="操作" width="120">
                                <template slot-scope="scope">
                                    <!-- <el-button type="text" @click="onEdit(scope.row)">查看</el-button> -->
                                    <el-button type="text" @click="onClose(scope.row)">关闭&退款</el-button>
                                    <!-- <el-button type="text" @click="onDelte(scope.row)" style="color: red;">删除</el-button> -->
                                </template>
                            </el-table-column>
                        </el-table>
                        <#include '/components/page.html' />
                    </template>
                </el-main>
            </el-container>
        </el-container>
        <#include "/yq/admin/components/footer.html" />
    </div>
    <#include "/yq/admin/components/scripts.html" />
    <script type="text/javascript">
    var vue = new Vue({
        el: '#app',
        data() {
            return {
                items: toJson(`${items![]}`),
                products: toJson(`${products}`),
                productId: '${productId!}' ? Number('${productId!}') : '',
                isDone: '${isDone!}' ? Number('${isDone!}') : '',
                isClosed: '${isClosed!}' ? Number('${isClosed!}') : ''
            }
        },
        mounted: function() {},
        methods: {
            onAdd() {
                location.href = '/yq/admin/item/info'
            },
            onEdit(info) {
                window.location.href = '/yq/admin/item/info?itemId=' + info.id;
            },
            onDelte(info) {
                this.$confirm('确定删除?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    var param = {
                        itemId: info.id
                    }
                    axiosRequest(param, '/yq/admin/group/delete', '')
                }).catch(() => {});
            },
            onClose(info){
                this.$confirm('确定?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    var param = {
                        groupId: info.id
                    }
                    axiosRequest(param, '/yq/admin/group/close', '')
                }).catch(() => {});

            },
            onDateChange(val) {
                var keys = [
                    { key: 'startDate', value: val[0] },
                    { key: 'endDate', value: val[1] }
                ]
                goPage(1, keys)
            },
            onSearch() {
                var self = this;
                var keys = [
                    { key: 'productId', value: self.productId },
                    { key: 'isDone', value: self.isDone },
                    { key: 'isClosed', value: self.isClosed }
                ]
                // if (self.dateRange != null && self.dateRange.length > 1) {
                //     keys.push({ key: 'startTime', value: self.dateRange[0] });
                //     keys.push({ key: 'endTime', value: self.dateRange[1] });
                // } else {
                //     keys.push({ key: 'startTime', value: '' });
                //     keys.push({ key: 'endTime', value: '' });
                // }
                goPage(1, keys);
            }
        },
        filters: {
            fmt(date) {
                return date
            }
        }
    })
    </script>
    <script>
    // vue.tableData = ${items!};
    </script>
    <style type="text/css">
    .search {
        margin-top: 10px;
    }
    </style>
</body>

</html>